﻿using System.Activities;

namespace Foulds.Calculator.StateMachine.Publisher
{
    /// <summary>
    /// This code activity is used to publish changes to the display.
    /// </summary>
    public sealed class PublishDisplay : CodeActivity
    {
        #region Properties
        public InArgument<CalculatorPublisher> Publisher { get; set; }
        public InArgument<string> InputDisplay { get; set; }
        public InArgument<string> ExpressionDisplay { get; set; }
        #endregion

        #region Execute
        /// <summary>
        /// Execute the code activity.
        /// </summary>
        /// <param name="context">The contect of the activity.</param>
        protected override void Execute(CodeActivityContext context)
        {
            // obtain the input arguments
            CalculatorPublisher publisher = context.GetValue(this.Publisher);
            string inputDisplay = context.GetValue(this.InputDisplay);
            string expressionDisplay = context.GetValue(this.ExpressionDisplay);

            // publish the event
            if (publisher != null)
                publisher.OnDisplayChange(inputDisplay, expressionDisplay);
        }
        #endregion
    }
}
